<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@ include file="/include/service-base-header.jsp" %>
    <title>desk</title>
</head>
<body>

<div class="container-fluid">
    <%@include file="/include/top-header.jsp" %>

    <div class="row">
        <%--//左侧面板--%>
        <div class="col-md-3 s-left-board">
            <%@include file="/include/left-board.jsp" %>
        </div>

        <%--右侧内容--%>
        <div class="col-md-9">
            <div class="card card-plain">
                <div class="card-header card-header-primary">
                    <div class="card-title">Withdraw Details</div>
                    <p class="card-category">&nbsp;</p>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                            <tr>
                                <th class="text-primary">
                                    #
                                </th>
                                <th class="text-primary">
                                    Withdrawal time
                                </th>
                                <th class="text-primary">
                                    Withdrawal amount
                                </th>
                                <th class="text-primary">
                                    Confirm withdrawal time
                                </th>
                                <th class="text-primary">
                                    Withdrawal to account
                                </th>
                                <th class="text-primary">
                                    Status
                                </th>
                            </tr>
                            </thead>
                            <tbody id="tbody">

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <nav aria-label="page">
                <ul class="pagination justify-content-center" id="p1">
                </ul>
            </nav>
        </div>
    </div>
</div>
</body>
<script>

    var withdraw_list;

    //每页显示条数
    var page_count = 15;

    getWithdrawList();

    /**
     * 获取提现列表
     */
    function getWithdrawList() {


        var salesId = "<%=session.getAttribute("salesId")%>";

        $.ajax({
            url: baseUrl.base + 'sales/withdrawList',
            type: 'post',
            data: {'saleId': salesId},
            success: function (data) {

                if (data.code == 0) {

                    var res = data.results;

                    withdraw_list = res;

                    cutPagination(1);

                    // 配置分页
                    $("#p1").pagination({
                        totalData: withdraw_list.length,
                        showData: page_count,
                        callback: function (idx) {
                            cutPagination(idx);
                        }
                    });
                }
            }
        })
    }

    function cashStateStr(cashState) {
        // 1：审核中2：成功3：失败
        if (cashState == 1) {
            return "review";
        }
        if (cashState == 2) {
            return "success";
        }
        if (cashState == 3) {
            return "failure";
        }
        return "";
    }

    /**
     * 分页
     * @param page 从1开始
     */
    function cutPagination(page) {

        var start = (page - 1) * page_count;
        var end = start + page_count;

        if (end > withdraw_list.length) {
            end = withdraw_list.length;
        }


        $("#tbody").empty();
        for (var i = start; i < end; i++) {
            var withdraw = withdraw_list[i];

            var createTime = withdraw.createTime;
            var cashMoney = withdraw.cashMoney;
            var endTime = withdraw.endTime;
            var cashAccount = withdraw.cashAccount;
            var cashState = withdraw.cashState;

            var tr = document.createElement("tr");
            var td = document.createElement("td");
            var text = document.createTextNode(i + 1 + "");
            td.appendChild(text);
            tr.appendChild(td);

            var td = document.createElement("td");
            var text = document.createTextNode(timestampToTime(createTime));
            td.appendChild(text);
            tr.appendChild(td);

            var td = document.createElement("td");
            var text = document.createTextNode(cashMoney + "KSH");
            td.appendChild(text);
            tr.appendChild(td);

            var td = document.createElement("td");
            var text = document.createTextNode(timestampToTime(endTime));
            td.appendChild(text);
            tr.appendChild(td);

            var td = document.createElement("td");
            var text = document.createTextNode(cashAccount);
            td.appendChild(text);
            tr.appendChild(td);

            var td = document.createElement("td");
            var text = document.createTextNode(cashStateStr(cashState));
            td.appendChild(text);
            tr.appendChild(td);

            document.getElementById("tbody").append(tr);
        }
    }

</script>
</html>